#pragma once 
#include <Wire.h>
#include <math.h>
#include <Arduino.h>
#include "WiFi.h"
#include "PubSubClient.h"
#include "Ticker.h"
#include "ArduinoJson.h"


struct SensorData
{
    short Depth;
    short DO_Perc;
    short DO_Val;
    short DO_PH;
    short DO_Temp;
    short COD_Val;
    short COD_Temp;
    short COD_PH;
    float longi;
    float lati;
    String time_str;
};


class MQTTFunc
{
private:
    WiFiClient espClient;           //创建一个WIFI连接客户端
    PubSubClient * client; // 创建一个PubSub客户端, 传入创建的WIFI客户端
    Ticker tim1;                    //定时器,用来循环上传数据
    Ticker tim2;                    //定时器,用来循环上传数据
    float temp;
    float humi;
    int postMsgId = 0; //记录已经post了多少条
    void * SendData;
public:
    MQTTFunc();
    ~MQTTFunc();
    void setupWifi(void);
    // void sendTempAndHumi(void);
    void SendString(String data);
    String DecodeSensorData2JsonString(SensorData data);
    void clientReconnect(void);
    void init(std::function<void(char*, unsigned char*, unsigned int)> DecodeDataFunc, void (* SendDataFunc)(void));
    void checkWIFI(void);
    void checkConnect(void);
};